package com.epfresh.utils;

import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.epfresh.R;
import com.epfresh.api.utils.LocalDisplay;
import com.epfresh.bean.HomeCommTag;

import java.util.List;

/**
 * Created by zhaozhenqiang on 2016/4/1.
 */
public class TagsUtils {
    public static void initTags(LinearLayout ll, List<HomeCommTag> tags ){
        int roundRadius = 15; // 8px not dp
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        ll.removeAllViews();
        int flagColor;
        for (int i = 0; i < tags.size(); i++) {
            GradientDrawable gd = (GradientDrawable) ll.getResources().getDrawable(R.drawable.btnstylegreen);
            gd.setCornerRadius(roundRadius);
            flagColor = ColorUtils.parseColor(tags.get(i).getColor());
            TextView flag = new TextView(ll.getContext());
            flag.setLines(1);
            flag.setText(tags.get(i).getName());
            flag.setTextSize(10);
            //flag.setPadding(5,2,10,2);
            lp.setMargins(0, 0, 10, 0);
            flag.setLayoutParams(lp);
            flag.setTextColor(flagColor);
            gd.setStroke(LocalDisplay.dp2px(1f), flagColor);
            flag.setBackgroundDrawable(gd);
            ll.addView(flag);
        }
    }
}
